const mongoose = require('mongoose')
const mongoUri = process.env.NODE_ENV === 'development' ? `mongodb://localhost:27017/rc` : `mongodb://mongo/rc`
mongoose.connect(mongoUri, { useNewUrlParser: true, useFindAndModify: false })

const connection = mongoose.connection
connection.on('error', () => {
  console.error(`MongoDB: ${mongoUri} connect failed!`)
})
connection.once('open', () => {
  console.log(`MongoDB: ${mongoUri} connect success!`)
})

module.exports = connection
